import request from './axios'

/**
 * 根据 id 获取指定文章
 */
export const getArticleById = articleId => {
  return request({
    url: `/v1_0/articles/${articleId}`
  })
}

/**
 * 添加关注
 */
export const addFollow = userId => {
  return request({
    method: 'POST',
    url: '/v1_0/user/followings',
    data: {
      target: userId
    }
  })
}

/**
 * 取消关注
 */
export const deleteFollow = userId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/user/followings/${userId}`
  })
}

/**
 * 收藏文章
 */
export const addCollect = target => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target
    }
  })
}

/**
 * 取消收藏文章
 */
export const deleteCollect = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/collections/${target}`
  })
}

/**
 * 文章点赞
 */
export const addLike = articleId => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target: articleId
    }
  })
}

/**
 * 取消文章点赞
 */
export const deleteLike = articleId => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${articleId}`
  })
}

/**
 * 获取评论(包括文章的评论以及对评论的评论)
 */
export function getComments(params) {
  return request({
    url: "/v1_0/comments",
    params
  });
}

/**
 * 对评论或评论回复点赞
 */
export function addCommentLike(commentId) {
  return request({
    method: "POST",
    url: "/v1_0/comment/likings",
    data: {
      target: commentId
    }
  });
}

/**
 * 取消对评论或评论回复点赞
 */
export function deleteCommentLike(commentId) {
  return request({
    method: "DELETE",
    url: `/v1_0/comment/likings/${commentId}`
  });
}

/**
 * 添加评论或评论回复
 */
export function addComment(data) {
  return request({
    method: "POST",
    url: "/v1_0/comments",
    data
  });
}

/**
 * 获取当前用户收藏文章列表
 */
export function getUserCollectArticles (params) {
  return request({
    url: '/v1_0/article/collections',
    params
  })
}

/**
 * 获取当前用户阅读历史文章列表
 */
export function getUserHistoryArticles (params) {
  return request({
    url: '/v1_0/user/histories',
    params
  })
}

/**
 * 获取用户用户发表文章列表
 * http://ttapi.research.itcast.cn/app/v1_0/users/1/articles?page=1&per_page=10
 */
export function getUserSendArticles (id,params) {
  return request({
    url: `/v1_0/users/${id}/articles`,
    params
  })
}